/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frame.BanHang;

import dao.PhieuNhapKhoDAO;
import java.beans.PropertyVetoException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import pojo.Nhanvien;
import pojo.Phieunhapkho;

/**
 *
 * @author Quan
 */
public class QLPhieuNhapKho extends myclass.MyAdminFrame {

    private DefaultTableModel tablemodel;

    /**
     * Creates new form QLPhieuNhapKho
     */
    public QLPhieuNhapKho(Nhanvien nv) {
        super(nv);
        initComponents();
        this.setTitle("Quản Lý Phiếu Nhập Kho");

        this.tablemodel = new DefaultTableModel();
        tablemodel.addColumn("STT");
        tablemodel.addColumn("Người Lập Phiếu");
        tablemodel.addColumn("Ngày Lập Phiếu");
        tablemodel.addColumn("Tổng Giá Trị");
        tablemodel.addColumn("Của Hàng");
        tablemodel.addColumn("Ghi Chú");
        jTable1.setModel(tablemodel);
        LoadPhieuNhap();
    }

    private void LoadPhieuNhap() {
        PhieuNhapKhoDAO phieuNhapKhoDAO = new PhieuNhapKhoDAO();
        List<Phieunhapkho> ls = null;
        try {
            ls = phieuNhapKhoDAO.LayDanhSach();
        } catch (Exception ex) {
            Logger.getLogger(QLPhieuNhapKho.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < ls.size(); i++) {
            Phieunhapkho phieunhapkho = ls.get(i);
            tablemodel.addRow(new Object[]{
                        i + 1,
                        phieunhapkho.getNhanvien(),
                        phieunhapkho.getNgaylapphieu(),
                        phieunhapkho,
                        phieunhapkho.getCuahang(),
                        phieunhapkho.getGhichu()
                    });
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setIconifiable(true);

        jButton1.setText("Thêm");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Sửa");

        jButton3.setText("Xóa");

        jButton4.setText("Đóng");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3)
                        .addGap(18, 18, 18)
                        .addComponent(jButton4)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        this.hide();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        PhieuNhapKho phieuNhapKho = new PhieuNhapKho(this.nv);
        this.getParent().add(phieuNhapKho);
        try {
            phieuNhapKho.ShowWithMaximunSize();
        } catch (PropertyVetoException ex) {
            Logger.getLogger(QLPhieuNhapKho.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
